package priv.mill.factory;

import java.util.HashMap;
import java.util.Map;

public class AnimalFactory {
/**
 * 空间的浪费
 * 时间上浪费
 * @param name
 * @return
 */
	
	
	
	private static Map<String, Amimal> map=new HashMap<String, Amimal>();
	
    public static Amimal getAnimal(String name){
    	Amimal amimal = map.get(name);
    	if(amimal==null){
    		Amimal newObje = newObje(name);
    		amimal=newObje;
    		map.put(name, newObje);
    	}
        return amimal;
    }

	private static Amimal newObje(String name) {
		if("金毛".equals(name))
    		return new JinMao();
    	if("吉娃娃".equals(name))
    		return new JiWaWa();
    	if("贵宾".equals(name))
    		return new GuiBin();
		return new NullAmimal();
	}

}
